/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package creditcardapp.model;

import framework.model.Account;
import framework.model.Customer;
import framework.model.Factory;
import framework.model.IFunctor;
import framework.model.IPredicate;

/**
 *
 * @author LD
 */
public abstract class CreditCardAccount extends Account {

    private String creditCardNumber;
    private String expiredDate;
    private double lastMonthBalance;
    //
    protected double minPaymentRate;
    //
    public String getCreditCardNumber() {
        return creditCardNumber;
    }

    @Override
    public String toString() {
        return getType();
    }

    public String getExpiredDate() {
        return expiredDate;
    }

    public CreditCardAccount(Customer cust, String ccNumber, String expiredDate) {
        super(cust);
        this.creditCardNumber = ccNumber;
        this.expiredDate = expiredDate;
    }

    public double getLastMonthBalance() {
        return lastMonthBalance;
    }

    public double getTotalMonthlyCredits() {
        IPredicate mPredicate = Factory.getInstance().createPredicate(IPredicate.T_MONTHLY);
        IPredicate dPredicate = Factory.getInstance().createPredicate(IPredicate.T_DEPOSIT);
        IFunctor sf = Factory.getInstance().createFunctor(IFunctor.T_SUM);
        entries.doAll(sf, mPredicate, dPredicate);
        return sf.getValue();
    }

    public double getTotalMonthlyCharges() {
        IPredicate mPredicate = Factory.getInstance().createPredicate(IPredicate.T_MONTHLY);
        IPredicate wPredicate = Factory.getInstance().createPredicate(IPredicate.T_WITHDRAW);
        IFunctor sf = Factory.getInstance().createFunctor(IFunctor.T_SUM);
        entries.doAll(sf, mPredicate, wPredicate);
        return sf.getValue();
    }

    // abstract functions
    public abstract double getNewMonthlyBalance();
    public abstract double getNewMonthlyAmountDue();
    public abstract String getType();

    @Override
    public String generateMonthlyReport() {
        StringBuilder sb = new StringBuilder();
        sb.append("Customer: ").append(customer.getField("name")).append('\n');
        sb.append("Address: ").append(customer.getAddress().toString()).append('\n');
        sb.append("CC Number: ").append(this.creditCardNumber).append('\n');
        sb.append("Account Type: ").append(getType()).append('\n');
        sb.append("Previous Balance: ").append(this.getLastMonthBalance()).append("\n");
        sb.append("Total Credits: ").append(this.getTotalMonthlyCredits()).append("\n");
        sb.append("Total Charges: ").append(this.getTotalMonthlyCharges()).append("\n");
        sb.append("New Balance: ").append(this.getNewMonthlyBalance()).append("\n");
        sb.append("Total Amount Due: ").append(this.getNewMonthlyAmountDue()).append("\n");
        return sb.toString();
    }    
}
